{include file='_header'}
<style>
    .popover{
        width:170px;
        font-size:12px;
        line-height: 21px;
        color: #0d0706;
    }
    .popover span{
        color: #b9b9b9;
    }
    .nickname{
        display: inline-block;
        max-width:200px;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
        vertical-align: middle;
    }

    .tooltip-inner{
        border:none;
    }
</style>
<div class="page-header">当前位置：<span class="text-primary">会员列表</span></div>
<div class="page-content">
    <form action="" method="get" class="form-horizontal table-search" role="form">
        <div class="page-toolbar">
            <span class="pull-left">
                {:tpl_daterange('time', array('sm'=>true, 'placeholder'=>'注册时间'),true);}
            </span>
            <div class="input-group">
                <span class="input-group-select">
                    <select name='level' class='form-control'>
                        <option value=''>等级</option>
                        {foreach name='levels' item='l'}
                            <option value="{$l['id']}" {if $level==$l['id']}selected{/if}>{$l['levelname']}</option>
                        {/foreach}
                    </select>
                </span>
                <span class="input-group-select">
                    <select name='groupid' class='form-control'>
                        <option value=''>分组</option>
                        {foreach name='groups' item='g'}
                            <option value="{$g['id']}" {if $groupid==$g['id']}selected{/if}>{$g['groupname']}</option>
                        {/foreach}
                    </select>
                </span>
                <span class="input-group-select">
                    <select name='isblack' class='form-control'>
                        <option value=''>黑名单</option>
                        <option value='0' {if $_GET['isblack']=='0'}selected{/if}>否</option>
                        <option value='1' {if $_GET['isblack']=='1'}selected{/if}>是</option>
                    </select>
                </span>
                <input type="text" class="form-control" name="realname" value="{$realname}" placeholder="可搜索昵称/姓名/手机号/ID">
                <span class="input-group-btn">
                    <button class="btn  btn-primary" type="submit"> 搜索</button>
                    <button type="submit" name="export" value="1" class="btn btn-success ">导出</button>
                </span>
            </div>
        </div>
    </form>

    {if count($list) < 0}
        <div class="panel panel-default">
            <div class="panel-body empty-data">未查询到相关数据</div>
        </div>
    {else}
        <div class="row">
            <div class="col-md-12">
                <div class="page-table-header">
                    <input type="checkbox">
                    <div class="btn-group">
                        <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch' data-href="{:url('admin/member/setblack',array('isblack'=>1))}">
                            <i class="icow icow-heimingdan2"></i>设置黑名单
                        </button>
                        <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch' data-href="{:url('admin/member/setblack',array('isblack'=>0))}">
                            <i class="icow icow-yongxinyonghu"></i> 取消黑名单
                        </button>
                        <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch-remove' data-confirm="确认要删除?" data-href="{:url('admin/member/delete')}">
                            <i class="icow icow-shanchu1"></i> 批量删除
                        </button>
                        <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch-group'> <i class="icow icow-fenzuqunfa"></i>修改分组</button>
                        <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch-level'><i class="icow icow-cengjiguanli"></i> 修改等级</button>
                    </div>
                </div>
                <table class="table table-responsive">
                    <thead>
                    <tr>
                        <th style="width:25px;"></th>
                        <th style="width: 250px;">会员</th>
                        <th style="">等级/分组</th>
                        <th style="">注册时间</th>
                        <th style="">积分/余额</th>
                        <th style="">成交</th>
                        <th style="width: 125px;text-align: center;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        {foreach name='list' item='row'}
                        <tr>
                            <td style="position: relative; ">
                                <input type='checkbox' value="{$row['id']}" class="checkone"/></td>
                            <td style="overflow: visible">
                                <div rel="pop" style="display: flex"  data-content=" <span>ID: </span>{$row['id']} </br>
                                <span>真实姓名：</span> {if empty($row['realname'])}未填写{else}{$row['realname']}{/if}
                                <br/>
                                <span>手机号：</span>{if !empty($row['mobileverify'])}{$row['mobile']}{else}未绑定{/if} <br/>
                                <span>状态:</span>  {if $row['isblack']==1}黑名单{else}正常{/if} ">
                                   <img class="img-40" src="{$row['avatar']}" style='border-radius:50%;border:1px solid #efefef;' onerror="this.src='/public/static/images/noface.png'" />
                                   <span style="display: flex;flex-direction: column;justify-content: center;align-items: flex-start;padding-left: 5px">
                                       <span class="nickname">
                                           {if empty($row['nickname'])}未更新{else}{$row['nickname']}{/if}
                                       </span>
                                       {if $row['isblack']==1}
                                            <span class="text-danger">黑名单<i class="icow icow-heimingdan1"style="color: #db2228;margin-left: 2px;font-size: 13px;"></i></span>
                                       {/if}
                                   </span>
                                </div>
                            </td>
                            <td>{if empty($row['levelname'])}普通会员{else}{$row['levelname']}{/if}
                                <br/>{if empty($row['groupname'])}无分组{else}{$row['groupname']}{/if}
                            </td>
                            <td>{:date("Y-m-d",$row['createtime'])}<br/>{:date("H:i:s",$row['createtime'])}</td>
                            <td><span >积分:  <span style="color: #5097d3">{:intval($row['credit1'])}</span> </span>
                                <br/><span>余额: <span class="text-warning">{:price_format($row['credit2'],2)} </span></span></td>

                            <td><span>订单: {$row['ordercount']}</span>
                                <br/><span> 金额: <span class="text-warning">{:floatval($row['ordermoney'])}</span></span></td>
                            <td style="overflow:visible;text-align: center;">
                                <div class="btn-group">
                                    <a class="btn  btn-op btn-operation" href="{:url('admin/member/detail',array('id' => $row['id']));}" title="">
                                        <span data-toggle="tooltip" data-placement="top" title="" data-original-title="会员详情">
                                            <i class='icow icow-bianji2'></i>
                                        </span>
                                    </a>
                                    <a class="btn  btn-op btn-operation" href="{:url('admin/order/olist_all', array('searchfield'=>'member','keyword'=>$row['nickname']))}"
                                       title=''>
                                       <span data-toggle="tooltip" data-placement="top" title="" data-original-title="会员订单">
                                           <i class='icow icow-dingdan2'></i>
                                        </span>
                                    </a>
                                    <!-- <a class="btn  btn-op btn-operation" data-toggle="ajaxModal" href="{:url('admin/finance/recharge', array('type'=>'credit1','id'=>$row['id']))}" title=''>
                                        <span data-toggle="tooltip" data-placement="top" title="" data-original-title="充值">
                                           <i class='icow icow-31'></i>
                                        </span>
                                    </a> -->
                                    <a class="btn btn-op btn-operation" data-toggle='ajaxRemove' href="{:url('admin/member/delete',array('id' => $row['id']));}" data-confirm="确定要删除该会员吗？">
                                         <span data-toggle="tooltip" data-placement="top" title="" data-original-title="删除会员">
                                           <i class='icow icow-shanchu1'></i>
                                        </span>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                    <tfoot>
                    <tr>
                        <td><input type="checkbox"></td>
                        <td colspan="3">
                            <div class="btn-group">
                                <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch' data-href="{:url('admin/member/setblack',array('isblack'=>1))}">
                                    <i class="icow icow-heimingdan2"></i>设置黑名单
                                </button>
                                <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch' data-href="{:url('admin/member/setblack',array('isblack'=>0))}">
                                    <i class="icow icow-yongxinyonghu"></i> 取消黑名单
                                </button>
                                <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch-remove' data-confirm="确认要删除?" data-href="{:url('admin/member/delete')}">
                                    <i class="icow icow-shanchu1"></i> 批量删除
                                </button>
                                <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch-group'> <i class="icow icow-fenzuqunfa"></i>修改分组</button>
                                <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch-level'><i class="icow icow-cengjiguanli"></i> 修改等级</button>
                            </div>
                        </td>
                        <td colspan="3" style="text-align: right">
                            {$pager}
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    {/if}
</div>
<div id="modal-change"  class="modal fade form-horizontal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">{if !empty($group['id'])}编辑{else}添加{/if}会员分组</h4>
            </div>
            <div class="modal-body">

                <div class="form-group batch-level" style="display: none;">
                    <label class="col-sm-2 control-label must">会员等级</label>
                    <div class="col-sm-9 col-xs-12">
                        <select name="batch-level" class="form-control">
                            <option value="0">{$default_levelname}</option>
                            {foreach name='levels' item='level'}
                                <option value="{$level['id']}">{$level['levelname']}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>

                <div class="form-group batch-group" style="display: none;">
                    <label class="col-sm-2 control-label must">会员分组</label>
                    <div class="col-sm-9 col-xs-12">
                        <select name="batch-group" class="form-control">
                            <option value="0">无分组</option>
                            {foreach name='groups' item='group'}
                                <option value="{$group['id']}">{$group['groupname']}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" type="submit" id="modal-change-btn">提交</button>
                <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
            </div>
        </div>
    </div>
</div>

<script language="javascript">
    require(['bootstrap'], function () {
        $("[rel=pop]").popover({
            trigger: 'manual',
            placement: 'right',
            title: $(this).data('title'),
            html: 'true',
            content: $(this).data('content'),
            animation: false
        }).on("mouseenter", function () {
            var _this = this;
            $(this).popover("show");
            $(this).siblings(".popover").on("mouseleave", function () {
                $(_this).popover('hide');
            });
        }).on("mouseleave", function () {
            var _this = this;
            setTimeout(function () {
                if (!$(".popover:hover").length) {
                    $(_this).popover("hide")
                }
            }, 100);
        });
    });
    $("[data-toggle='batch-group'], [data-toggle='batch-level']").click(function () {
        var toggle = $(this).data('toggle');
        $("#modal-change .modal-title").text(toggle=='batch-group'?"批量修改会员分组":"批量修改会员等级");
        $("#modal-change").find("."+toggle).show().siblings().hide();
        $("#modal-change-btn").attr('data-toggle', toggle=='batch-group'?'group':'level');
        $("#modal-change").modal();
    });
    $("#modal-change-btn").click(function () {
        var _this = $(this);
        if(_this.attr('stop')){
            return;
        }
        var toggle = $(this).data('toggle');
        var ids = [];
        $(".checkone").each(function () {
            var checked = $(this).is(":checked");
            var id = $(this).val();
            if(checked && id){
                ids.push(id);
            }
        });
        if(ids.length<1){
            tip.msgbox.suc("请选择要批量操作的会员");
            return;
        }
        var option = $("#modal-change .batch-"+toggle+" option:selected");
        var level = option.val();
        var levelname = option.text();
        tip.confirm("确定要将选中会员移动到 "+levelname+" 吗？", function () {
            _this.attr('stop', 1).text("操作中...");
            $.post(biz.url('admin/member/changelevel'),{
                level: level,
                ids: ids,
                toggle: toggle
            }, function (ret) {
                $("#modal-change").modal('hide');
                if(ret.status==1){
                    tip.msgbox.suc("操作成功");
                    setTimeout(function () {
                        location.reload();
                    },1000);
                }else{
                    tip.msgbox.err(ret.result.message);
                }
            }, 'json')
        });
    });
</script>
{include file='_footer'}